﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class ProfileDAO
    
    {
        public List<aspnet_Profile> LayDanhSach()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Profiles
                       select c;
            return list.ToList();
        }

        public aspnet_Profile LayTheoId(Guid Id)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Profiles
                       where c.UserId == Id
                       select c;
            
            aspnet_Profile Result = list.Single();
            return Result;

        }


        public void Them(aspnet_Profile temp)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.aspnet_Profiles.InsertOnSubmit(temp);
            EFashionDB.SubmitChanges();

        }

        public void Xoa(aspnet_Profile temp)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Profiles
                       where c.UserId == temp.UserId
                       select c;
            aspnet_Profile Result = list.Single();
            EFashionDB.aspnet_Profiles.DeleteOnSubmit(Result);
            EFashionDB.SubmitChanges();


        }

        public void CapNhat(aspnet_Profile temp)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var list = from c in EFashionDB.aspnet_Profiles
                       where c.UserId == temp.UserId
                       select c;

            foreach (aspnet_Profile u in EFashionDB.aspnet_Profiles)
            {
                u.PropertyNames = temp.PropertyNames;
                u.PropertyValuesBinary = temp.PropertyValuesBinary;
                u.PropertyValuesString = temp.PropertyValuesString;
                u.LastUpdatedDate = temp.LastUpdatedDate;
            }

            EFashionDB.SubmitChanges();

        }


    }
}
